package com.dingding.service.share;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.dingding.facde.share.IShareActivityFacade;
import com.dingding.facde.share.dto.CheckIsShareResult;
import com.dingding.facde.share.dto.RegActivityResult;
import com.dingding.facde.share.dto.StartShareResult;
import com.dingding.service.share.biz.IShareActivityService;
import com.dingding.service.share.dao.IActivityShareDao;

/**
 * @Description:有关分享推广活动的接口
 * @author fengshuonan
 * @date 2016年9月5日 下午2:15:26
 * @version 叮叮搭车
 * @since 2.4
 */
@Component("shareActivityFacade")
public class ShareActivityFacadeImpl implements IShareActivityFacade {

	@Resource(name = "shareActivityService")
	private IShareActivityService shareActivityService;

	@Resource(name = "activityShareDao")
	private IActivityShareDao activityShareDao;

	/**
	 * @Description:获取某个用户是否开启了某个分享活动
	 * @param userId
	 *            用户id
	 * @param activityId
	 *            活动id
	 * @author fengshuonan
	 * @return CheckIsShareResult 结果的封装
	 * @since 2.4
	 */
	@Override
	public CheckIsShareResult checkIsShare(String userId, String activityId) {

		return this.shareActivityService.checkIsShare(userId, activityId);
	}

	/**
	 * @Description:开起活动分享
	 * @param activityId
	 *            活动id
	 * @param gifts
	 *            活动所选的礼品
	 * @author fengshuonan
	 * @return StartShareResult
	 * @since 2.4
	 */
	@Override
	public StartShareResult startShare(String activityId, String userId, String[] gifts) {

		return this.shareActivityService.startShare(activityId, userId, gifts);
	}

	/**
	 * @Description:针对于活动的用户注册
	 * @author fengshuonan
	 * @return RegActivityResult
	 * @since 2.4
	 */
	@Override
	@Transactional(propagation = Propagation.REQUIRED)
	public RegActivityResult regUser4Activity(String activityId, String telephone, String messageCode, String shareKey,
			String openId) {

		return this.shareActivityService.regUser4Activity(activityId, telephone, messageCode, shareKey, openId);
	}

	/**
	 * @Description:发送短信验证码
	 * @author fengshuonan
	 * @since 2.4
	 */
	@Override
	public boolean sendPhoneMsg(String telephone) {

		return this.activityShareDao.sendPhoneMessage(telephone);
	}

	/**
	 * @Description:验证验证码是否正确
	 * @param telephone
	 *            电话号码
	 * @param code
	 *            验证码
	 * @author fengshuonan
	 * @since 2.4
	 */
	@Override
	public boolean isCodeRight(String telephone, String code) {

		// 判断验证码是否正确
		return this.activityShareDao.isMsgCodeTrue(telephone, code);
	}

}
